﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: TwoSampleZTest.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2012-09-06 11:39 AM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using BOL.Linq.Descriptive;
using BOL.Maths.Distributions;

namespace BOL.Maths.Statistics.HypothesisTest
{
    public sealed class TwoSampleZTest : TwoSampleMeanTestBase
    {
        #region Constructors

        public TwoSampleZTest(TestType type, double alpha, double mu12, IEnumerable<double> sample1, IEnumerable<double> sample2)
            : base(type, alpha, mu12, sample1, sample2)
        {
            Distribution = new GaussianDistribution();
        }

        public TwoSampleZTest(TestType type, double mu12, IEnumerable<double> sample1, IEnumerable<double> sample2) : this(type, 0.05, mu12, sample1, sample2) { }

        public TwoSampleZTest(double alpha, double mu12, IEnumerable<double> sample1, IEnumerable<double> sample2) : this(TestType.TwoSided, alpha, mu12, sample1, sample2) { }

        public TwoSampleZTest(double mu12, IEnumerable<double> sample1, IEnumerable<double> sample2) : this(TestType.TwoSided, 0.05, mu12, sample1, sample2) { }

        #endregion

        #region Protected methods

        protected override double MeanDifferenceStandardError()
        {
            return Math.Sqrt(Sample1.Variance() / SampleSize1 + Sample2.Variance() / SampleSize2);
        }

        #endregion
    }

    public sealed class PariedTwoSampleZTest : OneSampleZTest
    {
        #region Constructor

        public PariedTwoSampleZTest(TestType type, double alpha, double mu12, IEnumerable<double> sample1, IEnumerable<double> sample2)
            : base(type, alpha, mu12, sample1.Zip(sample2, (s1, s2) => s1 - s2)) { }

        #endregion
    }
}
